<template>
    <section class="jumbotron">
      <h3 class="jumbotron-heading">Search Github Users</h3>
      <div>
        <input type="text" v-model="keywords" placeholder="enter the name you search"/>
        &nbsp;
        <button @click="getUsers">Search</button>
      </div>
    </section>
</template>

<script>
// import axios from 'axios';
export default {
    name:'Search',
    data(){
        return{
            keywords:''
        }
    },
    methods:{
        getUsers(){
            this.$bus.$emit('search',{isFirst:false,isLoading:true,errorMsg:'',userData:[]})
            this.$http.get(`https://api.github.com/search/users?q=${this.keywords}`) .then((result) => {
            //console.log('#请求成功',result.data);
            this.$bus.$emit('search',{isFirst:false,isLoading:false,errorMsg:'',userData:result.data.items})
            }).catch((err) => {
            console.log('#请求失败',err.message);
            this.$bus.$emit('search',{isFirst:false,isLoading:false,errorMsg:err.message,userData:[]})
            });
           
        }
    }
}
</script>

<style>

</style>